package com.cwj.algorithm.graph;

import java.util.Deque;

/**
 * @author chenwujie
 * @date 2020-12-22 14:02
 */
public class DepthFirstSearch {
    private Graph graph;
    private boolean[] marked;
    private int count;

    public DepthFirstSearch(Graph graph){
        this.graph = graph;
        marked = new boolean[graph.getV()];
    }

    public void dfs(int v){
        System.out.println(v);
        marked[v] = true;
        Deque<Integer> vertexes = graph.getVertexes(v);
        for (Integer vertex : vertexes) {
            if(!marked[vertex]){
                dfs(vertex);
            }
        }
        count++;
    }

    public boolean marked(int v){
        return marked[v];
    }

    public int getCount(){
        return count;
    }
}
